package com.cntcdt.api.service.impl;

import java.util.Date;

import com.cntcdt.api.db.dao.ReturnCdbOperateDao;
import com.cntcdt.api.db.model.ReturnCdbOperateModel;
import com.cntcdt.api.service.ReturnCdbOperateService;

public class ReturnCdbOperateServiceImpl implements ReturnCdbOperateService {

	@Override
	public ReturnCdbOperateModel findByCDB(String cdb) {
		ReturnCdbOperateModel returnCdbOperate = ReturnCdbOperateDao.getInstance().findByCDB(cdb);
		if(returnCdbOperate == null){
			ReturnCdbOperateModel returnCdbOperate2 = new ReturnCdbOperateModel();
			returnCdbOperate2.setAddTime(new Date());
			returnCdbOperate2.setCdb(cdb);
			returnCdbOperate2.setCheckHistoryId(0);
			returnCdbOperate2.setReturnDescribe("");
			returnCdbOperate2.setOperate("失踪充电宝自动创建");
			returnCdbOperate2.setUpdateTime(new Date());
			returnCdbOperate2.setUserId(0);
			int id = ReturnCdbOperateDao.getInstance().insert(returnCdbOperate2);
			returnCdbOperate2.setId(id);
			returnCdbOperate = returnCdbOperate2;
		}
		return returnCdbOperate;
	}

	@Override
	public ReturnCdbOperateModel findByCheckHistoryId(int checkHisotryId) {
		return ReturnCdbOperateDao.getInstance().findByCheckHistoryId(checkHisotryId);
	}

	@Override
	public ReturnCdbOperateModel findById(int id) {
		return ReturnCdbOperateDao.getInstance().findByPrimaryKey(id);
	}

	@Override
	public boolean updateModel(ReturnCdbOperateModel returnCdbOperate) {
		return ReturnCdbOperateDao.getInstance().update(returnCdbOperate);
	}

}
